package com.形为型模式.命令模式;

import javax.swing.*;

/**
 * 抽象命令类 早餐
 */
interface Breakfast{
    void cooking();
}

/**
 * 肠粉 具体命令
 */
class ChangFen implements  Breakfast{
    ChangFenChef changFenChef = new ChangFenChef();
    @Override
    public void cooking() {
        System.out.println("火爆肠粉一碗");
        changFenChef.cooking();
    }
}

/**
 *河粉 具体命令
 */
class HeFen implements  Breakfast{
    HeFenChef heFenChef  = new HeFenChef();
    @Override
    public void cooking() {
        System.out.println("酸辣河粉一碗");
        heFenChef.cooking();

    }
}

/**
 * 馄饨 具体命令
 */
class HunTun implements  Breakfast{
    HunTunChef hunTunChef = new HunTunChef();
    @Override
    public void cooking() {
        System.out.println("龙肉馄饨一碗");
        hunTunChef.cooking();
    }
}

/**
 * 肠粉厨师 命令接收者
 */
class ChangFenChef extends JFrame {
    private static final long serialVersionUID = 1L;
    JLabel l=new JLabel();
    ChangFenChef()
    {
        super("煮肠粉");
        l.setIcon(new ImageIcon("src/img/ChangFen.jpg"));
        this.add(l);
        this.setLocation(30, 30);
        this.pack();
        this.setResizable(false);
        this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    }
    void cooking(){
        System.out.println("火爆肠粉出锅啦");
        this.setVisible(true);
    }
}

/**
 * 馄饨厨师 接收者
 */
class HunTunChef extends JFrame{
    private static final long serialVersionUID=1L;
    JLabel l=new JLabel();
    HunTunChef()
    {
        super("煮馄饨");
        l.setIcon(new ImageIcon("src/img/HunTun.jpg"));
        this.add(l);
        this.setLocation(350, 50);
        this.pack();
        this.setResizable(false);
        this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    }
    void cooking(){
        System.out.println("酸辣馄饨出锅啦");
        this.setVisible(true);
    }
}

/**
 * 河粉厨师 接收者
 */
class HeFenChef extends JFrame{
    private static final long serialVersionUID=1L;
    JLabel l=new JLabel();
    HeFenChef()
    {
        super("煮河粉");
        l.setIcon(new ImageIcon("src/img/HeFen.jpg"));
        this.add(l);
        this.setLocation(200, 280);
        this.pack();
        this.setResizable(false);
        this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    }
    void cooking(){
        System.out.println("龙肉河粉出锅啦");
        this.setVisible(true);
    }
}

/**
 * 服务员 调用者
 */
class Waiter{
    private Breakfast changFen,hunTun,heFen;
    void setChangFen(Breakfast f){
        this.changFen = f;
    }
    void setHeFen(Breakfast f){
       this.heFen = f;
    }
    void setHunTun(Breakfast f){
        this.hunTun = f;

    }
    void chooseChangFen(){
        changFen.cooking();;
    }
    void chooseHunTun(){
        hunTun.cooking();
    }
    void chooseHeFen(){
        heFen.cooking();
    }
}
/**
 * 早餐的命令模式
 */
public class CommandBreakFast {

    public static void main(String[] args) {
        Breakfast f = new HeFen();
        Waiter w = new Waiter();
        w.setHeFen(f);
        w.chooseHeFen();
        f = new ChangFen();
        w.setChangFen(f);
        w.chooseChangFen();
        f = new HunTun();
        w.setHunTun(f);
        w.chooseHunTun();
    }
}
